
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<style>
.ui-widget,.ui-widget .ui-widget {
	font-size: 11px !important;
}
</style>
	<title>Vendas</title>
	<link rel="stylesheet" type="text/css" href="estilos.css" />
</h:head>
<body>
	<h:form id="form">
		<p:panel id="mVendaPanel" style="border: none;">
			<h2>Cadastro de Venda</h2>
			<h:panelGrid columns="6" cellpadding="2" style="border: 2px;">
				<h:outputText value="Nota Fiscal" />
				<h:outputText value="Serie" />
				<h:outputText value="Cliente" />
				<h:outputText value="" />
				<h:outputText value="" />
				<h:outputLabel value="Cond.Pag. do Cliente" />

				<p:inputMask id="mVendaNotaFiscal" value="#{beanVenda.venda.nota}"
					maxlength="4" size="10" mask="999.999.999" />
				<p:inputMask id="mVendaSerie" value="#{beanVenda.venda.serie}"
					size="5" mask="999" />
				<p:inputText id="mVendaIdCliente"
					value="#{beanVenda.venda.cliente.id}" size="5">
					<p:ajax event="change" listener="#{beanVenda.hotFindCliente}"
						process="@this" update="mVendaCliente, mVendaCondicao" />
				</p:inputText>
				<p:inputText id="mVendaCliente"
					value="#{beanVenda.venda.cliente.nome}" size="50" disabled="true"
					binding="#{beanVenda.cliente}" />
				<p:commandButton icon="ui-icon-search"
					onclick="dConsultaCliente.show()" />
				<p:inputText id="mVendaCondicao"
					value="#{beanVenda.venda.cliente.condPagamento.descricao}"
					size="15" disabled="true" />
			</h:panelGrid>

			<br></br>

			<p:panel id="mVendaItensVenda" header="Produtos">

				<h:panelGrid columns="7" cellpadding="2">

					<h:outputText value="Codigo" />
					<h:outputText value="Produto*" />
					<h:outputText value="" />
					<h:outputText value="Quantidade*" />
					<h:outputText value="Preço Unitario" />
					<h:outputText value="Desconto" />
					<h:outputText value="" />

					<p:inputText id="mVendaIdProduto"
						value="#{beanVenda.item.produto.id}" maxlength="40" size="5">
						<p:ajax event="change" listener="#{beanVenda.hotFindProduto}"
							process="@this" update="mVendaProduto, mVendaPrecoUni" />
					</p:inputText>
					<p:inputText id="mVendaProduto"
						value="#{beanVenda.item.produto.descricao}" size="50"
						disabled="true" binding="#{beanVenda.produto}" />

					<p:commandButton id="mVendaSelesctProduto" icon="ui-icon-search"
						title="Selecionar Produto" onclick="dConsultaProduto.show() "
						update="mVendaProdutos">
						<f:setPropertyActionListener target="#{beanProduto.venda}"
							value="true"></f:setPropertyActionListener>
					</p:commandButton>

					<p:inputText id="mVendaQuantidade"
						value="#{beanVenda.item.quantidade}" size="5" />
					<p:inputText id="mVendaPrecoUni"
						value="#{beanVenda.item.produto.precoVenda}" size="7"
						disabled="true" />
					<p:inputText id="mVendaDesc" value="#{beanVenda.item.desconto}"
						size="5" />
					<p:commandButton id="addProduto" icon="ui-icon-plus"
						action="#{beanVenda.addItem}" title="Adicionar"
						update="mVendaItensVenda, mVendaSubTotal, mVendaTotal" />
				</h:panelGrid>

				<br></br>

				<p:dataTable emptyMessage="A venda nao possui produtos."
					value="#{beanVenda.itens}" var="item">
					<p:column headerText="Descricao">
						<h:outputText value="#{item.produto.descricao}" />
					</p:column>
					<p:column headerText="Quantidade">
						<h:outputText value="#{item.quantidade}" />
					</p:column>
					<p:column headerText="Preço Uni">
						<h:outputText value="#{item.precoUni}" />
					</p:column>
					<p:column headerText="Desconto">
						<h:outputText value="#{item.desconto}" />
					</p:column>
					<p:column headerText="Preco Total">
						<h:outputText value="#{item.valor}" />
					</p:column>
					<p:column width="10">
						<p:commandButton icon="ui-icon-trash"
							action="#{beanVenda.removeItem}"
							update=":mVendaForm:mVendaItensVenda">
							<f:setPropertyActionListener target="#{beanVenda.item}"
								value="#{item}" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>

			<br></br>
			<p:separator />

			<h:panelGrid columns="3" cellpadding="2" style="float: right;">
				<h:outputText value="Sub Total" />

				<h:outputText value="Desconto ($)" />

				<h:outputText value="Total" />

				<p:inputText id="mVendaSubTotal" value="#{beanVenda.venda.subTotal}"
					size="10" disabled="true" />

				<p:inputText id="mVendaDesconto" value="#{beanVenda.venda.desconto}"
					size="7">
					<p:ajax event="change" listener="#{beanVenda.atualizaTotal}"
						process="@this" update="mVendaTotal" />
				</p:inputText>

				<p:inputText id="mVendaTotal" value="#{beanVenda.venda.total}"
					size="7" disabled="true" />
			</h:panelGrid>

			<br></br>
			<br></br>
			<br></br>
			<br></br>
			<p:separator />

			<h:panelGrid columns="3" style="float: right;">
				<p:commandButton id="mVendaFinalizaVenda" value="Finalizar Venda"
					onclick="dCondVenda.show()" />
				<p:commandButton id="mVendaLimpar" value="Limpar"
					action="#{beanVenda.reinit}" update="form" />
				<p:commandButton id="mVendaVoltar" value="Voltar"
					onclick="history.back()" />
			</h:panelGrid>


			<h:panelGrid columns="4" cellpadding="2" style="float: left;">
				<h:outputText value="Emissao" />
				<p:inputText id="mVendaDataCad" value="#{beanVenda.venda.criacao}"
					size="7" disabled="true">
					<f:convertDateTime pattern="dd/MM/yyyy" />
				</p:inputText>

				<h:outputText value="Cancelamento" />

				<p:inputText id="mVendaDataAlteracao"
					value="#{beanVenda.venda.cancelamento}" size="7" disabled="true">
					<f:convertDateTime pattern="dd/MM/yyyy" />
				</p:inputText>
			</h:panelGrid>
		</p:panel>


		<p:dialog header="Finalizar Venda" widgetVar="dCondVenda"
			id="mVendaDCondPagamento" resizable="false">
			<ui:include src="/condPagamento/pFinalizaVenda.xhtml"></ui:include>
		</p:dialog>

		<p:dialog header="Consultar Produto" widgetVar="dConsultaProduto"
			id="mVendaDConsultaProduto" resizable="false">
			<p:outputPanel id="mVendaProdutos">
				<ui:include src="/produto/pConsultaProdutoVenda.xhtml"></ui:include>
			</p:outputPanel>
		</p:dialog>

		<p:dialog header="Consultar Cliente" widgetVar="dConsultaCliente"
			id="mVendaConsultaCliente" resizable="false">
			<ui:include src="/cliente/pClienteVenda.xhtml"></ui:include>
		</p:dialog>
	</h:form>

</body>
</html>